import api from "../../api/login.js";
import {
  removeLoginInfo
} from '../../utils/loginInfo.js'
import premissonsFunc from '../../utils/permissions.js'

Page({
  data: {
    userInfo: {},
    token: wx.getStorageSync('accessToken') || ''
  },
  onShow() {
    // premissonsFunc().then(res => {
    //   if (res) {
    this.setData({
      token: wx.getStorageSync('accessToken') || '',
      userInfo: wx.getStorageSync('userInfo') ? JSON.parse(wx.getStorageSync('userInfo')) : {
        avatar: ''
      }
    })
    this.getUserInfo()
    // }
    // })
  },
  async getUserInfo() {
    if (wx.getStorageSync('accessToken')) {
      const res = await api.getUserInfo()
      console.log(3222222222, res)
      if (res.code === 0) {
        this.setData({
          userInfo: res.data.user
        })
      }
    }
  },
  async onLoginout() {
    const res = await api.logout()
    if (res.code === 0) {
      await removeLoginInfo()
      wx.reLaunch({
        url: '/pages/login/index',
      })
    }
  },
  onPasswork() {
    wx.navigateTo({
      url: '/pages/passwork/index',
    })
  },
  onShareAppMessage(res) {
    return {
      title: '广州源之创食品有限公司',
      path: '/pages/my/index',
      imageUrl: 'https://www.yuanzhichuang.top/image/image.jpg',
    }
  },
  onShareTimeline(res) {
    return {
      title: '广州源之创食品有限公司',
      path: '/pages/my/index',
      imageUrl: 'https://www.yuanzhichuang.top/image/image.jpg',
    }
  }
})